/*
 * FileName: proxy.cc
 * Author: 李波(Edwin Lee)
 * Date: 2024-07-16 21:11:28
 * Version: 1.0
 * Description:代理模式：通过代理类，来控制实际对象的访问权限 
 */
#include <iostream>
using namespace std;

class MovieSite
{
public:
	virtual void freeMovie() = 0;     //免费电影
	virtual void vipMovie() = 0;      //vip电影
	virtual void ticketMovie() = 0;   //用券观看电影
};

//被代理类
class FixBugMovieSite:public MovieSite
{
public:
	virtual void freeMovie()
	{
		cout<<"观看免费电影"<<endl;
	}

	virtual void vipMovie()
	{
		cout<<"观看VIP电影"<<endl;
	}

	virtual void ticketMovie()
	{
		cout<<"用券观看电影"<<endl;
	}

};

// 代理类 代理FixBugMovieSite
class FreeMovieSiteProxy:public MovieSite
{
public:
	FreeMovieSiteProxy():pMovie_(new FixBugMovieSite())
	{}
	~FreeMovieSiteProxy()
	{
		if(nullptr != pMovie_)
			delete pMovie_;
	}

	virtual void freeMovie()
	{
		pMovie_->freeMovie();
	}

	virtual void vipMovie()
	{
		cout<<"权限不足，需要升级VIP，才能观看"<<endl;
	}

	virtual void ticketMovie()
	{
		cout<<"权限不足，需要电影票才能看"<<endl;
	}
private:
		MovieSite* pMovie_;
};
int main()
{
	FreeMovieSiteProxy fmovie;
	fmovie.freeMovie();
	fmovie.vipMovie();
	fmovie.ticketMovie();
	return 0;
}
